#include <iostream>
#include <string>
using namespace std;

string source;

string getSlicedString(int start, int stop, int step) {
    string result = "";
    start = start < 0 ? start + source.size() : start;
    stop = stop < 0 ? stop + source.size() : stop;
    for (int i = start; step > 0 ? i < stop : i > stop; i += step) {
        result += source[i];
    }
    return result;
}

int main() {
    getline(cin, source);
    int times; cin >> times;
    for (int i = 0; i < times; i++) {
        int arguCnt; cin >> arguCnt;
        if (arguCnt == 3) {
            int start, stop, step;
            cin >> start >> stop >> step;
            cout << getSlicedString(start, stop, step) << endl;
        }
        if (arguCnt == 2) {
            int start, stop; cin >> start >> stop;
            cout << getSlicedString(start, stop, 1) << endl;
        }
        if (arguCnt == 1) {
            int start; cin >> start;
            cout << getSlicedString(start, source.size(), 1) << endl;
        }
    }
    return 0;
}